package mrdemo011;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class EmpMap  extends Mapper<LongWritable, Text, Text, EmpData>{
	
	private Text k2 = new Text("");
	
	private EmpData empData = new EmpData();

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, EmpData>.Context context)
			throws IOException, InterruptedException {
		
		String line = value.toString();
		
		//输入的数据行，长度大于0则输出
		if(line!=null && line.trim().length()>0) {
			String[] split = line.trim().split("\t");
			if(split.length == 5) {
				//是员工数据
				k2.set(split[4]);
				empData.setFlag(0);
				empData.setEmpno(split[0]);
				empData.setEmpname(split[1]);
				context.write(k2, empData);
			}
			if(split.length == 3) {
				//是部门数据
				k2.set(split[0]);
				empData.setFlag(1);
				empData.setDeptno(split[0]);
				empData.setDeptname(split[1]);
				context.write(k2, empData);
			}
 		}
	}
}
